import { emailReg, passwordReg, usernameReg } from '@renderer/utlis/reg'
enum fromType {
  username = '用户名',
  password = '密码',
  repassword = '确认密码',
  email = '邮箱',
  verifyCode = '验证码'
}
enum fromVerify {
  username = '用户名应为中文或字母请在4-8位之间',
  password = '密码应包含字母与数字在6-12位之间',
  repassword = '两次密码不一致',
  email = '邮箱格式不正确'
}
// 验证表单是否为空
export const isEmpty = (formData, isLogin: boolean) => {
  if (isLogin) {
    delete formData.repassword
    delete formData.email
  }
  for (const key in formData) {
    if (formData[key] === '') {
      return {
        status: false,
        message: `${fromType[key]}不能为空`
      }
    }
  }
  return {
    status: true,
    message: ''
  }
}
// 验证表单正则是否通过
export const isVerify = (formData, isLogin: boolean) => {
  if (isLogin) {
    delete formData.repassword
    delete formData.email
  }
  const reg = {
    username: usernameReg,
    password: passwordReg,
    email: emailReg
  }
  if (!reg.username.test(formData.username)) {
    console.log(formData.username)
    return {
      status: false,
      message: fromVerify['username']
    }
  } else if (!reg.password.test(formData.password)) {
    return {
      status: false,
      message: fromVerify['password']
    }
  } else if (!reg.email.test(formData.email) && !isLogin) {
    return {
      status: false,
      message: fromVerify['email']
    }
  } else if (!formData.password === formData.repassword && !isLogin) {
    return {
      status: false,
      message: fromVerify['repassword']
    }
  } else {
    return {
      status: true,
      message: ''
    }
  }
}
